package com.pioneer.net;

import java.net.*;
import java.io.*;
import java.util.Map;
import java.util.HashMap;

public class Client{
	
	private Map clients= new HashMap();
	
	public Client(String host, int port) {		
		try {
			Socket socket = new Socket(host, port);
			BufferedReader in = new BufferedReader(new InputStreamReader((socket.getInputStream())));
			PrintWriter	out = new PrintWriter(socket.getOutputStream(),true);
			BufferedReader stdIn = new BufferedReader(
                                   new InputStreamReader(System.in));
			String userInput;
			//out.println("Got here");
			new Thread(new Listener(in)).start();
		
			while ((userInput = stdIn.readLine()) != null) {
			    out.println(userInput);
			    //System.out.println("echo: " + in.readLine());
			}
		}
		catch (IOException ex){
			ex.printStackTrace(System.err);
		}
		
	}
	
	class Listener
	implements Runnable{
		BufferedReader in;
		
		Listener(BufferedReader in){
			this.in = in;
		}			
		
		public void run() {
			try {
				String input = null;
				while ((input = in.readLine()) != null) {			    
				    System.out.println("echo: " + input);
				}
			}
			catch (IOException ex){
				ex.printStackTrace(System.err);
			}
		}
	}
	
	
	public static void main(String args[]){
		Client client = new Client("localhost",2004);		
	}
}